package com.example.livebroadcast.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.example.livebroadcast.model.LiveRedis;
import com.example.livebroadcast.service.LiveService;

@RestController
public class LiveController {
	
	@Autowired
	private LiveService liveService;

	@RequestMapping(value = "/liveList")
	public ModelAndView liveList() {
		return new ModelAndView("user/liveList");
	}
	
	@RequestMapping(value = "/publisher")
	public ModelAndView toPublisher(ModelMap modelMap) {
		modelMap.addAttribute("live", new LiveRedis());
		return new ModelAndView("user/publisher");
	}
	
	@RequestMapping(value = "/publisher", method = RequestMethod.POST)
	public ModelAndView publisher(@ModelAttribute(value = "live") LiveRedis liveRedis, ModelMap modelMap) {
		liveService.save(liveRedis);
		modelMap.addAttribute("liveList", liveService.getAll());
		return new ModelAndView("user/liveList");
	}
}
